// var IP = 'http://192.168.102.53:5005';

var toType;
var psize = 15;
var pnum = 1;

$(function () {

    function GetRequest() { // 调用url后的参数
        var url = window.location.search;
        var Request = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                Request[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
            }
        }
        toType = Request["type"] * 1;
        console.log(toType);
    }
    GetRequest();

    $.ajax({
        type: "get",
        // url: IP + "/all",
        url: "/all",
        dataType: "json",
        data: {
            type: toType,
            psize: psize,
            pnum: pnum
        },
        success: function (data) {
            console.log(data)
            showTable(data);
            // 分页
            $('#pagination').pagination({
                totalData: data.totalNum,
                showData: psize,
                coping: true,
                callback: function (i) {
                    var pnum = i;
                    // 点击页数时，请求列表数据
                    $.ajax({
                        type: "get",
                        // url: IP + "/all",
                        url: "/all",
                        dataType: "json",
                        data: {
                            type: toType,
                            psize: psize,
                            pnum: pnum
                        },
                        success: function (data) {
                            showTable(data);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.log('请求失败!');
                        }
                    })
                }
            }, function (api) {

            });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log('请求失败!');
        }
    })

    // 遍历列表
    function showTable(data) {
        $('#subject5 tbody').html("");
        var subjectTable = "";
        for (var i = 0; i < data.length; i++) {
            subjectTable += '<tr>';
            subjectTable += '<td>' + data[i].parm1 + '</span>';
            subjectTable += '<td>' + data[i].parm2 + '</span>';
            subjectTable += '<td>' + data[i].parm3 + '</span>';
            subjectTable += '<td>' + data[i].parm4 + '</span>';
            subjectTable += '<td>' + data[i].parm5 + '</span>';
            subjectTable += '<td>' + data[i].parm6 + '</span>';
            subjectTable += '<td>' + data[i].parm7 + '</span>';
            subjectTable += '<td>' + data[i].parm8 + '</span>';
            subjectTable += '<td>' + data[i].parm9 + '</span>';
            subjectTable += '<td>' + data[i].parm10 + '</span>';
            subjectTable += '<td>' + data[i].parm11 + '</span>';
            subjectTable += '<td>' + data[i].parm12 + '</span>';
            subjectTable += '<td>' + data[i].parm13 + '</span>';
            subjectTable += '<td>' + data[i].parm14 + '</span>';
            subjectTable += '<td>' + data[i].parm15 + '</span>';
            subjectTable += '<td>' + data[i].parm16 + '</span>';
            subjectTable += '<td>' + data[i].parm17 + '</span>';
            subjectTable += '<td>' + data[i].parm18 + '</span>';
            subjectTable += '<td>' + data[i].parm19 + '</span>';
            subjectTable += '<td>' + data[i].parm20 + '</span>';
            subjectTable += '</tr>';
        }
        $('#subject5 tbody').html(subjectTable);
    }
})